home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / getuse.arc / GETUSER.C
Text File  |  1988-02-06  |  6KB  |  207 lines

  1. /**********************************************************************
  2. **  GETUSER        Get Network User ID (Login Name)                  **
  3. **                                                                   **
  4. **  Program:       Commercial Loan System (CLS)                      **
  5. **  Module:        GETUSER.C                                         **
  6. **  Date:          March 26, 1987                                    **
  7. **  Developer:     GLENFED Financial Corporation                     **
  8. **  Programmer:    Thomas E. Scribner                                **
  9. **  Compile:       Small Model                                       **
  10. **  Children:                                                        **
  11. **  Link:                                                            **
  12. **                                                                   **
  13. **  Description:   This function is the Novell Network Log Function  **
  14. **                 E3h (16h) - Get a Connection's Information. This  **
  15. **                 call retrieves an object's log record from the    **
  16. **                 network and returns it to the calling station.    **
  17. **                                                                   **
  18. **  History:                                                         **
  19. **   11/23/87 tes  Mod to allow function to return UNKNOWN when the  **
  20. **                 network shell is loaded and user is not logged    **
  21. **                 into the network.                                 **
  22. **                                                                   **
  23. **   07/09/87 TES  Mod getname so that when not on net returns       **
  24. **                 UNKNOWN user name.                                **
  25. **                                                                   **
  26. ** (c)1987, GLENFED Financial Corporation                            **
  27. ** All Rights Reserved.                                              **
  28. **********************************************************************/
  29.  
  30. #define    LINT_ARGS
  31.  
  32. #include   <stdio.h>
  33. #include   <dos.h>
  34. #include   <string.h>
  35.  
  36. /*
  37. ** Novell Data Types
  38. */
  39.  
  40. typedef unsigned char        BYTE;
  41. typedef unsigned int         WORD,NATIVE;
  42. typedef unsigned long        LONG;
  43.  
  44. /*
  45. ** Request Packet Definition
  46. */
  47.  
  48. typedef struct {
  49.     NATIVE    PacketLength;
  50.     BYTE      Function;
  51.     BYTE      ConnectionNumber;
  52. }REQUESTPAK;
  53.  
  54. typedef REQUESTPAK far * lpREQUESTPAK;
  55.  
  56. /*
  57. ** Reply Packet Definition
  58. */
  59.  
  60. typedef struct {
  61.     NATIVE    ReturnLength;
  62.     LONG      UniqueID;
  63.     WORD      Type;
  64.     BYTE      ObjectName[48];
  65.     BYTE      LogTime[8];
  66. }REPLYPAK;
  67.  
  68.  
  69. typedef REPLYPAK far * lpREPLYPAK;
  70.  
  71. unsigned char GetConnection( void );
  72.  
  73.  
  74. #define    ERROR       -1
  75. #define    SUCCESS     0
  76.  
  77.  
  78. /*-----------------------------------------------------------------*/
  79. /* SendPacket      Make the Novell Function call with the Request  */
  80. /*                 and Reply Packet.                               */
  81. /*-----------------------------------------------------------------*/
  82. #ifdef MSC4
  83. SendPacket(lpRequest,lpReply)
  84. lpREQUESTPAK lpRequest;
  85. lpREPLYPAK lpReply;
  86. #else
  87. SendPacket( lpREQUESTPAK lpRequest, lpREPLYPAK lpReply  )
  88. #endif
  89. {
  90.     union REGS regs;
  91.     struct SREGS segregs;
  92.      int ret;
  93.     /*
  94.     ** DS:SI - Address of Request Buffer
  95.     */
  96.     segregs.ds = FP_SEG( lpRequest );
  97.     regs.x.si = FP_OFF( lpRequest );
  98.  
  99.     /*
  100.     ** ES:DI - Address of Reply Buffer
  101.     */
  102.     segregs.es = FP_SEG( lpReply );
  103.     regs.x.di = FP_OFF( lpReply );
  104.     
  105.     regs.h.ah = 0xE3;                  /* Function E3h - Get a */
  106.  
  107.     ret = intdosx(®s,®s,&segregs);     /* Int 21h */
  108.      return(regs.h.al);
  109.  
  110. }
  111.  
  112.  
  113.     
  114. /*-----------------------------------------------------------------*/
  115. /* GetConnection   - Get Connection is used to return the logical  */
  116. /*                   port number of the file server to which the   */
  117. /*                   station is connected.                         */
  118. /*-----------------------------------------------------------------*/ 
  119. unsigned char
  120. GetConnection()
  121. {
  122.     union REGS inregs,outregs;
  123.  
  124.     inregs.h.ah = 0xDC;
  125.     intdos(&inregs,&outregs);
  126.     return(outregs.h.al);
  127.  
  128. }
  129.  
  130. /*-----------------------------------------------------------------*/
  131. /* GetName         This function builds the request and reply      */
  132. /*                 packet for the SendPacket function.  It places  */
  133. /*                 the User Name in the username passed to it.     */
  134. /*-----------------------------------------------------------------*/
  135. int
  136. #ifdef MSC4
  137. GetName(UName)
  138. char     *UName;
  139. #else
  140. GetName( char *UName )
  141. #endif
  142. {
  143.    REQUESTPAK Packet1;
  144.    REPLYPAK Packet2;
  145.    int ret_code;
  146.  
  147.    ret_code = SUCCESS;
  148.    Packet1.PacketLength = 2;
  149.    Packet1.Function = 0x16;
  150.  
  151.    Packet1.ConnectionNumber = (BYTE)GetConnection();
  152.  
  153.    if(Packet1.ConnectionNumber == 0){
  154.        strcpy(UName,"UNKNOWN");
  155.    }else{
  156.        Packet2.ReturnLength = 62;
  157.        ret_code = SendPacket((lpREQUESTPAK)&Packet1,(lpREPLYPAK)&Packet2);
  158.        if( ret_code != SUCCESS)
  159.            strcpy(UName,"UNKNOWN");
  160.        else
  161.               strcpy(UName,Packet2.ObjectName);
  162.    }
  163.    return(ret_code);
  164. }
  165.  
  166.  
  167. /*
  168. #ifdef DEBUG
  169.  
  170. void
  171. main(argc,argv)
  172. int    argc;
  173. char   *argv[];
  174. {
  175.     char    TEST[25];
  176.  
  177.     GetName(TEST);
  178.     printf("The users name is %s",TEST);
  179.  
  180. }
  181.  
  182. #endif
  183.  
  184. */
  185.  
  186.  
  187. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  188. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  189. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  190. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  191. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  192. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  193. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  194. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  195. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  196. /* --- END OF FILE --- END OF FILE --- END OF FILE --- END OF FILE --- */
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.     
  207.